package com.project.m.api.busi.util.IdGenerator;

import com.project.m.api.busi.util.ParamHelper;
import com.project.m.api.busi.util.TimeUtil;

public class IdGenerator {
	public static String OrderID_Prefix_PAY = "31"; // 支付订单号
	public static String ORDERID_PREFIX_USER_CARD = "32"; // 用户卡片号
	public static String ORDERID_PREFIX_TRANSACTION = "33"; // 交易单号
	public static String ORDERID_PREFIX_SYSTEM_CARD = "34"; // 批量制卡卡号
	public static String ORDERID_PREFIX_COUPON = "35"; // 优惠券


	// 生成orderId
	static public String generateOrderId(String orderPrefix, String channelCode, String subType) {
		// 渠道代码
		String channel = "00" + channelCode;
		channel = channel.substring(channel.length() - 2, channel.length());
		// System.out.println("channel = " + channel);

		// 渠道子代码
		String subTypeStr = "0000" + subType;
		subTypeStr = subTypeStr.substring(subTypeStr.length() - 4, subTypeStr.length());
		// System.out.println("subTypeStr = " + subTypeStr);

		// 当前时间14位 yyyyMMddHHmmss
		String currTime = TimeUtil.getCurrTime("yyyyMMddHHmmss");
		// System.out.println("currTime = " + currTime);

		// 随机数10位
		String strRandom = ParamHelper.buildRandom(5) + "" + ParamHelper.buildRandom(5);

		// System.out.println("strRandom = " + strRandom);
		String out_trade_no = orderPrefix + channel + subTypeStr + currTime + strRandom;

		// System.out.println("out_trade_no = " + out_trade_no);
		// System.out.println("out_trade_no length = " + out_trade_no.length());

		return out_trade_no;
	}

	// 生成refundId
	static public String generateRefundId(String orderPrefix, String channelCode, String subType) {

		// 渠道代码
		String channel = "00" + channelCode;
		channel = channel.substring(channel.length() - 2, channel.length());
		// System.out.println("channel = " + channel);

		// 渠道子代码
		String subTypeStr = "0000" + subType;
		subTypeStr = subTypeStr.substring(subTypeStr.length() - 4, subTypeStr.length());
		// System.out.println("subTypeStr = " + subTypeStr);

		// 当前时间14位 yyyyMMddHHmmss
		String currTime = TimeUtil.getCurrTime("yyyyMMddHHmmss");
		// System.out.println("currTime = " + currTime);

		// 随机数10位
		String strRandom = ParamHelper.buildRandom(5) + "" + ParamHelper.buildRandom(5);
		String out_trade_no = orderPrefix + channel + subTypeStr + currTime + strRandom;

		// System.out.println("out_trade_no = " + out_trade_no);
		// System.out.println("out_trade_no length = " + out_trade_no.length());

		return out_trade_no;
	}

	// 生成批量制卡卡号
	static public String generateSystemCardId(String orderPrefix, String channelCode, String subType) {

		// 渠道代码
		String channel = "00" + channelCode;
		channel = channel.substring(channel.length() - 2, channel.length());
		// System.out.println("channel = " + channel);

		// 渠道子代码
		String subTypeStr = "0000" + subType;
		subTypeStr = subTypeStr.substring(subTypeStr.length() - 4, subTypeStr.length());
		// System.out.println("subTypeStr = " + subTypeStr);

		// 当前时间14位 yyyyMMddHHmmss
		String currTime = TimeUtil.getCurrTime("yyyyMMddHHmmss");
		// System.out.println("currTime = " + currTime);

		// 随机数10位
		String strRandom = ParamHelper.buildRandom(5) + "" + ParamHelper.buildRandom(5);
		String out_trade_no = orderPrefix + channel + subTypeStr + currTime + strRandom;

		// System.out.println("out_trade_no = " + out_trade_no);
		// System.out.println("out_trade_no length = " + out_trade_no.length());

		return out_trade_no;
	}
}
